package com.dr.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dr.pojo.User;
import com.dr.service.LoginService;

@Controller
public class LoginController {
	@Autowired
	LoginService loginService;

	/*
	 * index.jsp，跳转过来，加载登录页面
	 */
	@RequestMapping("/login")
	public String loginPage() throws Exception {
		return "login";
	}

	/*
	 * Login.jsp，单击【登录】按钮
	 */
	@RequestMapping("/loginSubmit")
	public String loginSubmit(HttpServletRequest request, User user) throws Exception {
		User loginUser = loginService.findUser(user);
		if (loginUser == null) {
			request.setAttribute("loginErrMsg", "用户名或密码错误，请重新输入！");
			return "login";
		} else {
			request.getSession().setAttribute("loginUser", loginUser);
			return "redirect:userManage/userList.action";
		}
	}

}
